#include "Comm.hpp"
int main()
{
    Fifo fifo(Path);
    int rfd = open(Path, O_RDONLY);
    if (rfd < 0)
    {
        cout << "erron:" << errno << "  errorString:" << strerror(errno) << endl;
        return 1;
    }
    // 如果写端没有被打开,但是读端先被打开了,此时读端就会被阻塞,直到写端被打开,读端open才会返回.
    cout<<"open file success!"<<endl;
    char buffer[1024];
    while (true)
    {
        int n = read(rfd, buffer, sizeof(buffer));
        if (n > 0)
        {
            // 读取成功
            buffer[n] = 0;
            cout << "client say:" << buffer << endl;
        }else if(n==0){
            cout<<"client quit, me too"<<endl;
            break;
        }else{
            cout << "Read fail: errno:" << errno << "  errorString:" << strerror(errno) << endl;
            break;
        }
    }
    close(rfd);
    return 0;
}